package com.blakebarrett.model.media
{
	import flash.filesystem.File;
	
	[Bindable]
	public class MediaInfo implements IMediaInfo
	{
		private var _src : String;
		private var _scale : Number;
		private var _originalWid : Number = 0;
		private var _originalHei : Number = 0;
		private var _currentWid : Number = 0;
		private var _currentHei : Number = 0;
		private var _currentXOffset : Number = 0;
		private var _currentYOffset : Number = 0;
		private var _regionWid : Number = 0;
		private var _regionHei : Number = 0;
		
		public function get source () : String {
			return _src;
		}
		public function set source( val:String ) : void {
			_src = val;
		}
		
		public function get scale () : Number {
			return _scale;
		}
		public function set scale (val:Number) : void{
			if ((val * originalWidth) >= minimumWidth && 
				(val * originalHeight >= minimumHeight)){
				_scale = val;
			} else {
				_scale = ScalarMediaInfo.scaleMediaToRegion( _originalWid, _originalHei, _regionWid, _regionHei );
				_currentWid = (_originalWid * _scale);
				_currentHei = (_originalHei * _scale);
			}
		}
		
		public function get minimumScale () : Number {
			return ScalarMediaInfo.scaleMediaToRegion( _originalWid, _originalHei, _regionWid, _regionHei );
		}
		
		public function scaleToFit () : void {
			scale = ScalarMediaInfo.scaleMediaToRegion( _originalWid, _originalHei, _regionWid, _regionHei );
			
			_currentWid = (_originalWid * _scale);
			_currentHei = (_originalHei * _scale);
		}
		
		public function get maximumX () : Number {
			return PositionalMediaInfo.maxX( _currentWid, _regionWid);
		}
		
		public function get maximumY () : Number {
			return PositionalMediaInfo.maxY( _currentHei, _regionHei);
		}
		
		public function get minimumX () : Number {
			return PositionalMediaInfo.minX( _currentWid, _regionWid);
		}

		public function get minimumY () : Number {
			return PositionalMediaInfo.minY( _currentHei, _regionHei);
		}

		public function get maximumWidth () : Number {
			return ScalarMediaInfo.maxWidth( _originalWid, _originalHei );
		}
		
		public function get maximumHeight () : Number {
			return ScalarMediaInfo.maxHeight( _originalWid, _originalHei );
		}
		
		public function get minimumWidth () : Number { 
			return ScalarMediaInfo.minWidth( _regionWid );
		}
		
		public function get minimumHeight () : Number {
			return ScalarMediaInfo.minHeight( _regionHei );
		}
		
		public function set originalWidth ( val : Number ) : void {
			_originalWid = val;
		}
		public function get originalWidth () : Number {
			return _originalWid;
		}
		
		public function set originalHeight ( val : Number ) : void {
			_originalHei = val;
		}
		public function get originalHeight () : Number {
			return _originalHei;
		}
		
		public function set currentWidth ( val : Number ) : void {
			_currentWid = val;
		}
		public function get currentWidth () : Number {
			return _currentWid;
		}
		
		public function set currentHeight ( val : Number ) : void {
			_currentHei = val;
		}
		public function get currentHeight () : Number {
			return _currentHei;
		}
		
		public function set currentXOffset ( val : Number ) : void {
			_currentXOffset = val;
		}
		public function get currentXOffset () : Number {
			return _currentXOffset;
		}
		
		public function set currentYOffset ( val : Number ) : void {
			_currentYOffset = val;
		}
		public function get currentYOffset () : Number {
			return _currentYOffset;
		}
		
		public function set regionWidth ( val : Number ) : void {
			_regionWid = val;
			if ( val < currentWidth ) {
				scaleToFit();
			}
		}
		public function get regionWidth () : Number {
			return _regionWid;
		}
		
		public function set regionHeight ( val : Number ) : void {
			_regionHei = val;
			if ( val < currentHeight ) {
				scaleToFit();
			}
		}
		public function get regionHeight () : Number {
			return _regionHei;
		}
	}
}